package cn.dansj.handler.interfaces;

import cn.dansj.annotation.MarkAsApi;
import cn.dansj.common.utils.enums.ResponseCode;
import cn.dansj.common.utils.json.DictMap;
import cn.dansj.common.utils.transfer.Md5Utils;
import cn.dansj.common.utils.transfer.Transformation;
import cn.dansj.exception.InterfaceResponseException;
import cn.dansj.handler.InterfaceHandler;
import cn.dansj.common.utils.transfer.Verification;

import java.util.Map;

@MarkAsApi
public class EdgeUpdateComponent extends InterfaceHandler {
    private static final String update = "update x_edge_component set `show`=? where id=?";
    private static final String delete = "delete from x_edge_component where id=?";

    @Override
    public Object execute(Map<String, Object> paramsMap) {
        String id = Transformation.toString(paramsMap.get("id"));
        if (Verification.checkNull(id)) throw new InterfaceResponseException(ResponseCode.Error.getStatusCode(), "未找到组件");
        if (!paramsMap.containsKey("status")){
            if (jdbcTemplate.update(delete, id) > 0) return true;
            throw new InterfaceResponseException(ResponseCode.Error.getStatusCode(), "未找到组件");
        }
        boolean status = Transformation.castToBoolean(paramsMap.get("status"));

        if (jdbcTemplate.update(update, status, id) > 0) return true;
        throw new InterfaceResponseException(ResponseCode.Error.getStatusCode(), "未找到组件");
    }
}